﻿<span style='font-size:11px; color:#000000; background:#ffffff; '><pre>
<span style='color:#800000; font-weight:bold; '>Protected</span> <span style='color:#800000; font-weight:bold; '>Sub</span> createPdfButton_Click<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>ByVal</span> sender <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Object</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>ByVal</span> e <span style='color:#800000; font-weight:bold; '>As</span> EventArgs<span style='color:#808030; '>)</span>
    <span style='color:#696969; '>' Create a PDF document</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> pdfDocument <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>New</span> Document<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>

    <span style='color:#696969; '>' Set license key received after purchase to use the converter in licensed mode</span>
    <span style='color:#696969; '>' Leave it not set to use the converter in demo mode</span>
    pdfDocument<span style='color:#008c00; '>.</span>LicenseKey <span style='color:#808030; '>=</span> <span style='color:#0000e6; '>"4W9+bn19bn5ue2B+bn1/YH98YHd3d3c="</span>

    <span style='color:#696969; '>' Add a PDF page to PDF document</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> pdfPage <span style='color:#800000; font-weight:bold; '>As</span> PdfPage <span style='color:#808030; '>=</span> pdfDocument<span style='color:#008c00; '>.</span>AddPage<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>

    <span style='color:#800000; font-weight:bold; '>Dim</span> htmlToPdfElement <span style='color:#800000; font-weight:bold; '>As</span> HtmlToPdfElement <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>Nothing</span>
    <span style='color:#800000; font-weight:bold; '>Try</span>
        <span style='color:#696969; '>' Add a default document header</span>
        AddHeader<span style='color:#808030; '>(</span>pdfDocument<span style='color:#808030; '>,</span> <span style='color:#0f4d75; '>True</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Add a default document footer</span>
        AddFooter<span style='color:#808030; '>(</span>pdfDocument<span style='color:#808030; '>,</span> <span style='color:#0f4d75; '>True</span><span style='color:#808030; '>,</span> <span style='color:#0f4d75; '>True</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Create a HTML to PDF element to add to document</span>
        htmlToPdfElement <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>New</span> HtmlToPdfElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> urlTextBox<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>Text</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Optionally set a delay before conversion to allow asynchonous scripts to finish</span>
        htmlToPdfElement<span style='color:#008c00; '>.</span>ConversionDelay <span style='color:#808030; '>=</span> <span style='color:#008c00; '>2</span>

        <span style='color:#696969; '>' Install a handler where to change the header and footer in pages generated by the HTML to PDF element</span>
        <span style='color:#800000; font-weight:bold; '>AddHandler</span> htmlToPdfElement<span style='color:#008c00; '>.</span>PrepareRenderPdfPageEvent<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>AddressOf</span> htmlToPdfElement_PrepareRenderPdfPageEvent

        <span style='color:#696969; '>' Add the HTML to PDF element to document</span>
        <span style='color:#696969; '>' This will raise the PrepareRenderPdfPageEvent event where the header can be changed per page</span>
        pdfPage<span style='color:#008c00; '>.</span>AddElement<span style='color:#808030; '>(</span>htmlToPdfElement<span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Save the PDF document in a memory buffer</span>
        <span style='color:#800000; font-weight:bold; '>Dim</span> outPdfBuffer<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span> <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Byte</span> <span style='color:#808030; '>=</span> pdfDocument<span style='color:#008c00; '>.</span>Save<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Send the PDF as response to browser</span>

        <span style='color:#696969; '>' Set response content type</span>
        Response<span style='color:#008c00; '>.</span>AddHeader<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"Content-Type"</span><span style='color:#808030; '>,</span> <span style='color:#0000e6; '>"application/pdf"</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Instruct the browser to open the PDF file as an attachment or inline</span>
        Response<span style='color:#008c00; '>.</span>AddHeader<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"Content-Disposition"</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>String</span><span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>Format</span><span style='color:#808030; '>(</span><span style='color:#0000e6; '>"attachment; filename=Change_Header_Footer_Per_Page.pdf; size={0}"</span><span style='color:#808030; '>,</span> outPdfBuffer<span style='color:#008c00; '>.</span>Length<span style='color:#008c00; '>.</span>ToString<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Write the PDF document buffer to HTTP response</span>
        Response<span style='color:#008c00; '>.</span>BinaryWrite<span style='color:#808030; '>(</span>outPdfBuffer<span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' End the HTTP response and stop the current page processing</span>
        Response<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>End</span><span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>Finally</span>
        <span style='color:#696969; '>' uninstall handler</span>
        <span style='color:#800000; font-weight:bold; '>RemoveHandler</span> htmlToPdfElement<span style='color:#008c00; '>.</span>PrepareRenderPdfPageEvent<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>AddressOf</span> htmlToPdfElement_PrepareRenderPdfPageEvent

        <span style='color:#696969; '>' Close the PDF document</span>
        pdfDocument<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>Close</span><span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>Try</span>
<span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>Sub</span>

<span style='color:#696969; '>''' &lt;summary></span>
<span style='color:#696969; '>''' The handler for HtmlToPdfElement.PrepareRenderPdfPageEvent event where you can set the visibility of header and footer</span>
<span style='color:#696969; '>''' in each page or you can add a custom header or footer in a page</span>
<span style='color:#696969; '>''' &lt;/summary></span>
<span style='color:#696969; '>''' &lt;param name="eventParams">The event parameter containin the PDF page to customize before rendering&lt;/param></span>
<span style='color:#800000; font-weight:bold; '>Private</span> <span style='color:#800000; font-weight:bold; '>Sub</span> htmlToPdfElement_PrepareRenderPdfPageEvent<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>ByVal</span> eventParams <span style='color:#800000; font-weight:bold; '>As</span> PrepareRenderPdfPageParams<span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>If</span> <span style='color:#808030; '>(</span>eventParams<span style='color:#008c00; '>.</span>PageNumber <span style='color:#808030; '>=</span> <span style='color:#008c00; '>1</span><span style='color:#808030; '>)</span> AndAlso changeHeaderAndFooterCheckBox<span style='color:#008c00; '>.</span>Checked <span style='color:#800000; font-weight:bold; '>Then</span>
        <span style='color:#696969; '>' Change the header and footer in first page with an alternative header and footer</span>

        <span style='color:#696969; '>' The PDF page being rendered</span>
        <span style='color:#800000; font-weight:bold; '>Dim</span> pdfPage <span style='color:#800000; font-weight:bold; '>As</span> PdfPage <span style='color:#808030; '>=</span> eventParams<span style='color:#008c00; '>.</span>Page

        <span style='color:#696969; '>' Add a custom header of 80 points in height to this page</span>
        <span style='color:#696969; '>' The default document header will be replaced in this page</span>
        pdfPage<span style='color:#008c00; '>.</span>AddHeaderTemplate<span style='color:#808030; '>(</span><span style='color:#008c00; '>80</span><span style='color:#808030; '>)</span>
        <span style='color:#696969; '>' Draw the page header elements</span>
        DrawAlternativePageHeader<span style='color:#808030; '>(</span>pdfPage<span style='color:#008c00; '>.</span>Header<span style='color:#808030; '>,</span> <span style='color:#0f4d75; '>True</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Add a custom footer of 80 points in height to this page</span>
        <span style='color:#696969; '>' The default document footer will be replaced in this page</span>
        pdfPage<span style='color:#008c00; '>.</span>AddFooterTemplate<span style='color:#808030; '>(</span><span style='color:#008c00; '>80</span><span style='color:#808030; '>)</span>
        <span style='color:#696969; '>' Draw the page header elements</span>
        DrawAlternativePageFooter<span style='color:#808030; '>(</span>pdfPage<span style='color:#008c00; '>.</span>Footer<span style='color:#808030; '>,</span> <span style='color:#0f4d75; '>True</span><span style='color:#808030; '>,</span> <span style='color:#0f4d75; '>True</span><span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>If</span>
<span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>Sub</span>

<span style='color:#696969; '>''' &lt;summary></span>
<span style='color:#696969; '>''' Add a header to document</span>
<span style='color:#696969; '>''' &lt;/summary></span>
<span style='color:#696969; '>''' &lt;param name="pdfDocument">The PDF document object&lt;/param></span>
<span style='color:#696969; '>''' &lt;param name="drawHeaderLine">A flag indicating if a line should be drawn at the bottom of the header&lt;/param></span>
<span style='color:#800000; font-weight:bold; '>Private</span> <span style='color:#800000; font-weight:bold; '>Sub</span> AddHeader<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>ByVal</span> pdfDocument <span style='color:#800000; font-weight:bold; '>As</span> Document<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>ByVal</span> drawHeaderLine <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Boolean</span><span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> headerHtmlUrl <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>String</span> <span style='color:#808030; '>=</span> Server<span style='color:#008c00; '>.</span>MapPath<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"~/DemoAppFiles/Input/HTML_Files/Header_HTML.html"</span><span style='color:#808030; '>)</span>

    <span style='color:#696969; '>' Create the document header template</span>
    pdfDocument<span style='color:#008c00; '>.</span>AddHeaderTemplate<span style='color:#808030; '>(</span><span style='color:#008c00; '>60</span><span style='color:#808030; '>)</span>

    <span style='color:#696969; '>' Create a HTML element to be added in header</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> headerHtml <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>New</span> HtmlToPdfElement<span style='color:#808030; '>(</span>headerHtmlUrl<span style='color:#808030; '>)</span>

    <span style='color:#696969; '>' Set the HTML element to fit the container height</span>
    headerHtml<span style='color:#008c00; '>.</span>FitHeight <span style='color:#808030; '>=</span> <span style='color:#0f4d75; '>True</span>

    <span style='color:#696969; '>' Add HTML element to header</span>
    pdfDocument<span style='color:#008c00; '>.</span>Header<span style='color:#008c00; '>.</span>AddElement<span style='color:#808030; '>(</span>headerHtml<span style='color:#808030; '>)</span>

    <span style='color:#800000; font-weight:bold; '>If</span> drawHeaderLine <span style='color:#800000; font-weight:bold; '>Then</span>
        <span style='color:#800000; font-weight:bold; '>Dim</span> headerWidth <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Single</span> <span style='color:#808030; '>=</span> pdfDocument<span style='color:#008c00; '>.</span>Header<span style='color:#008c00; '>.</span>Width
        <span style='color:#800000; font-weight:bold; '>Dim</span> headerHeight <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Single</span> <span style='color:#808030; '>=</span> pdfDocument<span style='color:#008c00; '>.</span>Header<span style='color:#008c00; '>.</span>Height

        <span style='color:#696969; '>' Create a line element for the bottom of the header</span>
        <span style='color:#800000; font-weight:bold; '>Dim</span> headerLine <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>New</span> LineElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> headerHeight <span style='color:#808030; '>-</span> <span style='color:#008c00; '>1</span><span style='color:#808030; '>,</span> headerWidth<span style='color:#808030; '>,</span> headerHeight <span style='color:#808030; '>-</span> <span style='color:#008c00; '>1</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Set line color</span>
        headerLine<span style='color:#008c00; '>.</span>ForeColor <span style='color:#808030; '>=</span> Color<span style='color:#008c00; '>.</span>Gray

        <span style='color:#696969; '>' Add line element to the bottom of the header</span>
        pdfDocument<span style='color:#008c00; '>.</span>Header<span style='color:#008c00; '>.</span>AddElement<span style='color:#808030; '>(</span>headerLine<span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>If</span>
<span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>Sub</span>

<span style='color:#696969; '>''' &lt;summary></span>
<span style='color:#696969; '>''' Add a footer to document</span>
<span style='color:#696969; '>''' &lt;/summary></span>
<span style='color:#696969; '>''' &lt;param name="pdfDocument">The PDF document object&lt;/param></span>
<span style='color:#696969; '>''' &lt;param name="addPageNumbers">A flag indicating if the page numbering is present in footer&lt;/param></span>
<span style='color:#696969; '>''' &lt;param name="drawFooterLine">A flag indicating if a line should be drawn at the top of the footer&lt;/param></span>
<span style='color:#800000; font-weight:bold; '>Private</span> <span style='color:#800000; font-weight:bold; '>Sub</span> AddFooter<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>ByVal</span> pdfDocument <span style='color:#800000; font-weight:bold; '>As</span> Document<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>ByVal</span> addPageNumbers <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Boolean</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>ByVal</span> drawFooterLine <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Boolean</span><span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> footerHtmlUrl <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>String</span> <span style='color:#808030; '>=</span> Server<span style='color:#008c00; '>.</span>MapPath<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"~/DemoAppFiles/Input/HTML_Files/Footer_HTML.html"</span><span style='color:#808030; '>)</span>

    <span style='color:#696969; '>' Create the document footer template</span>
    pdfDocument<span style='color:#008c00; '>.</span>AddFooterTemplate<span style='color:#808030; '>(</span><span style='color:#008c00; '>60</span><span style='color:#808030; '>)</span>

    <span style='color:#696969; '>' Set footer background color</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> backColorRectangle <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>New</span> RectangleElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> pdfDocument<span style='color:#008c00; '>.</span>Footer<span style='color:#008c00; '>.</span>Width<span style='color:#808030; '>,</span> pdfDocument<span style='color:#008c00; '>.</span>Footer<span style='color:#008c00; '>.</span>Height<span style='color:#808030; '>)</span>
    backColorRectangle<span style='color:#008c00; '>.</span>BackColor <span style='color:#808030; '>=</span> Color<span style='color:#008c00; '>.</span>WhiteSmoke
    pdfDocument<span style='color:#008c00; '>.</span>Footer<span style='color:#008c00; '>.</span>AddElement<span style='color:#808030; '>(</span>backColorRectangle<span style='color:#808030; '>)</span>

    <span style='color:#696969; '>' Create a HTML element to be added in footer</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> footerHtml <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>New</span> HtmlToPdfElement<span style='color:#808030; '>(</span>footerHtmlUrl<span style='color:#808030; '>)</span>

    <span style='color:#696969; '>' Set the HTML element to fit the container height</span>
    footerHtml<span style='color:#008c00; '>.</span>FitHeight <span style='color:#808030; '>=</span> <span style='color:#0f4d75; '>True</span>

    <span style='color:#696969; '>' Add HTML element to footer</span>
    pdfDocument<span style='color:#008c00; '>.</span>Footer<span style='color:#008c00; '>.</span>AddElement<span style='color:#808030; '>(</span>footerHtml<span style='color:#808030; '>)</span>

    <span style='color:#696969; '>' Add page numbering</span>
    <span style='color:#800000; font-weight:bold; '>If</span> addPageNumbers <span style='color:#800000; font-weight:bold; '>Then</span>
        <span style='color:#696969; '>' Create a text element with page numbering place holders &amp;p; and &amp; P;</span>
        <span style='color:#800000; font-weight:bold; '>Dim</span> footerText <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>New</span> TextElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>30</span><span style='color:#808030; '>,</span> <span style='color:#0000e6; '>"Page &amp;p; of &amp;P;  "</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>New</span> Font<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>New</span> FontFamily<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"Times New Roman"</span><span style='color:#808030; '>)</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>10</span><span style='color:#808030; '>,</span> GraphicsUnit<span style='color:#008c00; '>.</span>Point<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Align the text at the right of the footer</span>
        footerText<span style='color:#008c00; '>.</span>TextAlign <span style='color:#808030; '>=</span> HorizontalTextAlign<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>Right</span>

        <span style='color:#696969; '>' Set page numbering text color</span>
        footerText<span style='color:#008c00; '>.</span>ForeColor <span style='color:#808030; '>=</span> Color<span style='color:#008c00; '>.</span>Navy

        <span style='color:#696969; '>' Embed the text element font in PDF</span>
        footerText<span style='color:#008c00; '>.</span>EmbedSysFont <span style='color:#808030; '>=</span> <span style='color:#0f4d75; '>True</span>

        <span style='color:#696969; '>' Add the text element to footer</span>
        pdfDocument<span style='color:#008c00; '>.</span>Footer<span style='color:#008c00; '>.</span>AddElement<span style='color:#808030; '>(</span>footerText<span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>If</span>

    <span style='color:#800000; font-weight:bold; '>If</span> drawFooterLine <span style='color:#800000; font-weight:bold; '>Then</span>
        <span style='color:#800000; font-weight:bold; '>Dim</span> footerWidth <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Single</span> <span style='color:#808030; '>=</span> pdfDocument<span style='color:#008c00; '>.</span>Footer<span style='color:#008c00; '>.</span>Width

        <span style='color:#696969; '>' Create a line element for the top of the footer</span>
        <span style='color:#800000; font-weight:bold; '>Dim</span> footerLine <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>New</span> LineElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> footerWidth<span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Set line color</span>
        footerLine<span style='color:#008c00; '>.</span>ForeColor <span style='color:#808030; '>=</span> Color<span style='color:#008c00; '>.</span>Gray

        <span style='color:#696969; '>' Add line element to the bottom of the footer</span>
        pdfDocument<span style='color:#008c00; '>.</span>Footer<span style='color:#008c00; '>.</span>AddElement<span style='color:#808030; '>(</span>footerLine<span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>If</span>
<span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>Sub</span>

<span style='color:#696969; '>''' &lt;summary></span>
<span style='color:#696969; '>''' Draw the alternative page header elements</span>
<span style='color:#696969; '>''' &lt;/summary></span>
<span style='color:#696969; '>''' &lt;param name="headerTemplate">The page header template&lt;/param></span>
<span style='color:#696969; '>''' &lt;param name="drawHeaderLine">A flag indicating if a line should be drawn at the bottom of the header&lt;/param></span>
<span style='color:#800000; font-weight:bold; '>Private</span> <span style='color:#800000; font-weight:bold; '>Sub</span> DrawAlternativePageHeader<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>ByVal</span> headerTemplate <span style='color:#800000; font-weight:bold; '>As</span> Template<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>ByVal</span> drawHeaderLine <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Boolean</span><span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> headerHtmlUrl <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>String</span> <span style='color:#808030; '>=</span> Server<span style='color:#008c00; '>.</span>MapPath<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"~/DemoAppFiles/Input/HTML_Files/Header_Alt_HTML.html"</span><span style='color:#808030; '>)</span>

    <span style='color:#696969; '>' Create a HTML element to be added in header</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> headerHtml <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>New</span> HtmlToPdfElement<span style='color:#808030; '>(</span>headerHtmlUrl<span style='color:#808030; '>)</span>

    <span style='color:#696969; '>' Set the HTML element to fit the container height</span>
    headerHtml<span style='color:#008c00; '>.</span>FitHeight <span style='color:#808030; '>=</span> <span style='color:#0f4d75; '>True</span>

    <span style='color:#696969; '>' Add HTML element to header</span>
    headerTemplate<span style='color:#008c00; '>.</span>AddElement<span style='color:#808030; '>(</span>headerHtml<span style='color:#808030; '>)</span>

    <span style='color:#800000; font-weight:bold; '>If</span> drawHeaderLine <span style='color:#800000; font-weight:bold; '>Then</span>
        <span style='color:#800000; font-weight:bold; '>Dim</span> headerWidth <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Single</span> <span style='color:#808030; '>=</span> headerTemplate<span style='color:#008c00; '>.</span>Width
        <span style='color:#800000; font-weight:bold; '>Dim</span> headerHeight <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Single</span> <span style='color:#808030; '>=</span> headerTemplate<span style='color:#008c00; '>.</span>Height

        <span style='color:#696969; '>' Create a line element for the bottom of the header</span>
        <span style='color:#800000; font-weight:bold; '>Dim</span> headerLine <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>New</span> LineElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> headerHeight <span style='color:#808030; '>-</span> <span style='color:#008c00; '>1</span><span style='color:#808030; '>,</span> headerWidth<span style='color:#808030; '>,</span> headerHeight <span style='color:#808030; '>-</span> <span style='color:#008c00; '>1</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Set line color</span>
        headerLine<span style='color:#008c00; '>.</span>ForeColor <span style='color:#808030; '>=</span> Color<span style='color:#008c00; '>.</span>Gray

        <span style='color:#696969; '>' Add line element to the bottom of the header</span>
        headerTemplate<span style='color:#008c00; '>.</span>AddElement<span style='color:#808030; '>(</span>headerLine<span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>If</span>
<span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>Sub</span>

<span style='color:#696969; '>''' &lt;summary></span>
<span style='color:#696969; '>''' Draw the alternative page footer elements</span>
<span style='color:#696969; '>''' &lt;/summary></span>
<span style='color:#696969; '>''' &lt;param name="htmlToPdfConverter">The HTML to PDF Converter object&lt;/param></span>
<span style='color:#696969; '>''' &lt;param name="addPageNumbers">A flag indicating if the page numbering is present in footer&lt;/param></span>
<span style='color:#696969; '>''' &lt;param name="drawFooterLine">A flag indicating if a line should be drawn at the top of the footer&lt;/param></span>
<span style='color:#800000; font-weight:bold; '>Private</span> <span style='color:#800000; font-weight:bold; '>Sub</span> DrawAlternativePageFooter<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>ByVal</span> footerTemplate <span style='color:#800000; font-weight:bold; '>As</span> Template<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>ByVal</span> addPageNumbers <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Boolean</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>ByVal</span> drawFooterLine <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Boolean</span><span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> footerHtmlUrl <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>String</span> <span style='color:#808030; '>=</span> Server<span style='color:#008c00; '>.</span>MapPath<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"~/DemoAppFiles/Input/HTML_Files/Footer_Alt_HTML.html"</span><span style='color:#808030; '>)</span>

    <span style='color:#696969; '>' Create a HTML element to be added in footer</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> footerHtml <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>New</span> HtmlToPdfElement<span style='color:#808030; '>(</span>footerHtmlUrl<span style='color:#808030; '>)</span>

    <span style='color:#696969; '>' Set the HTML element to fit the container height</span>
    footerHtml<span style='color:#008c00; '>.</span>FitHeight <span style='color:#808030; '>=</span> <span style='color:#0f4d75; '>True</span>

    <span style='color:#696969; '>' Add HTML element to footer</span>
    footerTemplate<span style='color:#008c00; '>.</span>AddElement<span style='color:#808030; '>(</span>footerHtml<span style='color:#808030; '>)</span>

    <span style='color:#696969; '>' Add page numbering</span>
    <span style='color:#800000; font-weight:bold; '>If</span> addPageNumbers <span style='color:#800000; font-weight:bold; '>Then</span>
        <span style='color:#696969; '>' Create a text element with page numbering place holders &amp;p; and &amp; P;</span>
        <span style='color:#800000; font-weight:bold; '>Dim</span> footerText <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>New</span> TextElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>10</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>30</span><span style='color:#808030; '>,</span> <span style='color:#0000e6; '>"Page &amp;p; of &amp;P;"</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>New</span> Font<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>New</span> FontFamily<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"Times New Roman"</span><span style='color:#808030; '>)</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>10</span><span style='color:#808030; '>,</span> GraphicsUnit<span style='color:#008c00; '>.</span>Point<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Align the text at the right of the footer</span>
        footerText<span style='color:#008c00; '>.</span>TextAlign <span style='color:#808030; '>=</span> HorizontalTextAlign<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>Left</span>

        <span style='color:#696969; '>' Set page numbering text color</span>
        footerText<span style='color:#008c00; '>.</span>ForeColor <span style='color:#808030; '>=</span> Color<span style='color:#008c00; '>.</span>Navy

        <span style='color:#696969; '>' Embed the text element font in PDF</span>
        footerText<span style='color:#008c00; '>.</span>EmbedSysFont <span style='color:#808030; '>=</span> <span style='color:#0f4d75; '>True</span>

        <span style='color:#696969; '>' Add the text element to footer</span>
        footerTemplate<span style='color:#008c00; '>.</span>AddElement<span style='color:#808030; '>(</span>footerText<span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>If</span>

    <span style='color:#800000; font-weight:bold; '>If</span> drawFooterLine <span style='color:#800000; font-weight:bold; '>Then</span>
        <span style='color:#800000; font-weight:bold; '>Dim</span> footerWidth <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Single</span> <span style='color:#808030; '>=</span> footerTemplate<span style='color:#008c00; '>.</span>Width

        <span style='color:#696969; '>' Create a line element for the top of the footer</span>
        <span style='color:#800000; font-weight:bold; '>Dim</span> footerLine <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>New</span> LineElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> footerWidth<span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Set line color</span>
        footerLine<span style='color:#008c00; '>.</span>ForeColor <span style='color:#808030; '>=</span> Color<span style='color:#008c00; '>.</span>Gray

        <span style='color:#696969; '>' Add line element to the bottom of the footer</span>
        footerTemplate<span style='color:#008c00; '>.</span>AddElement<span style='color:#808030; '>(</span>footerLine<span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>If</span>
<span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>Sub</span>
</pre>
</span>